<?php
/**
 * Date: 2021/8/4
 * Time: 15:19
 * 后台用户登录
 */

namespace App\Http\Controllers\Admin;
use Illuminate\Http\Request;
use App\Model\LogModel;
use Symfony\Component\HttpFoundation\Response;



class Log
{

    /*
     * 获取日志错误
     */
    public function getLog(Request $request)
    {

        $page=$request->post('page');
        $limit=$request->post('limit');
        $date=$request->post('date');

        $res=LogModel::getLogin($page,$limit,$date);

        return json_encode(['code' => Response::HTTP_OK, 'msg' => '成功',"data"=>$res]);

    }


    /*
     * 获取日志文件
     */
    public function getFile(Request $request){
        $date=$request->post('date');

        if(!$date){
            $date=date('Y-m-d');
        }

        $config=config('secret');
        $dir=$config['file_log'].$date;

        $file=scandir($dir);
        $fileArray=[];
        foreach($file as $key=>$value){
            if(strlen($value)>10){
                $fileArray[]=$config['url'].'log/client/'.$date.'/'.$value;
           }
        }
        $fileArray=array_reverse($fileArray);
        return json_encode(['code' => Response::HTTP_OK, 'msg' => '成功',"data"=>$fileArray]);

    }




}